package java9_2;

/**
 * @author oldliu
 * @since 1.0
 */
public class People {
    private String name;
    private int age;

    public People() {

    }

    //    public People(String name, int age) throws Exception {
//        this.name = name;
//        //this.age = age;
//        setAge(age);
//    }
    public People(String name, int age) throws AgeException {
        this.name = name;
        //this.age = age;
        setAge(age);
//        try {
//            setAge(age);
//        } catch (AgeException e) {
//            //e.printStackTrace();
//            throw new AgeException(e);
//        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age > 0 && age < 100)
            this.age = age;
        else
            throw new AgeException("年龄设置错误！");
    }

    @Override
    public String toString() {
        return "人{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
